<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>快捷的给原型添加属性</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>
    
    <script type="text/javascript">
        // extend
        function User(name){
            this.name = name;
        }

        var libai = new User("李白");

        User.prototype.extend = function (obj){
            for(var i in obj){
                // 不存在属性
                if(!(i in this)){
                    this[i] = obj[i];
                }
            }
        }

        User.prototype.extend({
            age: 24,
            friends: [],
            sayName(){
                console.log(this.name);
            }
        })

        libai.sayName();
        console.log(libai.__proto__);
    </script>
</body>
</html>